package com.beimi.net;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.beimi.game.MJService;
import com.beimi.game.action.ProcessMessageAction;
import com.beimi.game.module.GameUserCmdModule;
import com.beimi.game.player.GamePlayer;
import com.beimi.game.service.GamePlayerMgr;
import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.listener.DataListener;

public class AbstractGameCmd implements DataListener<String> {
	protected static final Logger LOG = LoggerFactory.getLogger(AbstractRoomCmd.class);

	protected GamePlayerMgr playerGame;

	public void execute(MJService object, GamePlayer player, String data) {
		LOG.warn("unimplement {}", data);
	}

	public void execute(SocketIOClient client, String data) {
		LOG.warn("unimplement {}", data);
	}

	@Override
	public void onData(SocketIOClient client, String data, AckRequest ackSender) throws Exception {
		GamePlayer player = playerGame.getPlayer(client.getSessionId().toString());
		if (player == null) {
			execute(client, data);
		} else {
			player.getGame().getModule(GameUserCmdModule.class).add(new ProcessMessageAction(this, player, data));
		}
	}
}
